<?php
	require"db_connection.php";
	error_reporting(E_ALL ^ E_NOTICE);
	$limit = 15;
	
	$query ="SELECT
			  COUNT(*) as num
			  FROM
			  affiliate";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages['num'];
	
	$stages = 3;
	$page = mysql_real_escape_string($_GET['idx']);
	//$page = $_GET['idx'];
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
	}
	
	
	$q = mysql_query("SELECT
					affiliate.affiliateid,
					affiliate.companyname,
					affiliate.companyaddress,
					affiliate.companyemail,
					affiliate.landline,
					affiliate.faxno,
					affiliate.mobileno1,
					affiliate.contactname,
					affiliate.websiteurl,
					affiliate.contactemail,
					city.cityname,
					country.countryname
					FROM
					affiliate
					INNER JOIN city ON city.cityid = affiliate.cityid
					INNER JOIN country ON country.countryid = city.countryid
					ORDER BY affiliate.companyname, city.cityname, country.countryname
					LIMIT $start, $limit ");
	$acc_num = $start;
	$class_alternate = "";
	while($row = mysql_fetch_array($q)){
		$acc_num=$acc_num+1;
		echo"<tr class='".$class_alternate."'>
						<td>".$acc_num."</td>
						<td><b>".$row['companyname']."</b></td>
						<td>".$row['companyaddress']."</td>
						<td><a href='".$row['companyemail']."'>".$row['companyemail']."</a></td>
						<td>".$row['countryname']."</td>
						<td>".$row['landline']."</td>
						<td class='options-width'>
							<a href='view_affiliate_details.php?id=".$row['affiliateid']."' title='View Affiliate Info' class='icon-5 info-tooltip'></a>
							<a href='view_affiliate_rates.php?id=".$row['affiliateid']."' title='View Rates' class='icon-5 info-tooltip' style='margin-left:5px;'></a>
							<a href='view_affiliate_info.php?id=".$row['affiliateid']."' title=' View Info' class='icon-4 info-tooltip'></a>
							
						</td>
					</tr>";

		if($class_alternate == ""){
			$class_alternate = "alternate-row";
		}else{
			$class_alternate = "";
		}
	}
?>
